package com.atguigu.oss.controller;

import com.atguigu.oss.commonutils.R;
import com.atguigu.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;

/**
 * @author luomingliang
 * @date 2020/6/6 21:14
 */
@CrossOrigin
@RequestMapping("/eduoss/fileoss")
@RestController
public class OssController {

    @Autowired
    private OssService ossService;

    //上传头像方法
    @PostMapping
    public R uploadOssFile(MultipartFile file) {
        //获取上传文件 MultipartFile
        String url = null;
        try {
            url = ossService.uploadFileAvatar(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("头像上传路径:"+url);
        return R.ok().data("url", url);
    }
}
